Repository navigation
Use newer ruff style - #2031
Merged
Merged
Use newer ruff style#2031
Conversation
EliahKagan
marked this pull request as ready for review
May 30, 2025 17:06
This updates `ruff` in `.pre-commit-config.yaml` from 0.6.0 to 0.11.12, changes its `id` from the legacy `ruff` alias to `ruff-check` (which is better distinguished from `ruff-format`, which we also have a hook for), and applies the few style changes it newly recommends throughout the code. The style changes seem to make things slightly clearer overall. This also updates some other pre-commit hooks, but those don't require any changes to the code. Currently the `ruff` dependency in `requirements-dev.txt` doesn't specify a version, so no change is needed there. This update may be seen as bringing the `pre-commit` version in line with what users will usually have locally with `pip install -e ".[test]"`. The `pre-commit` hooks are how linting is currently done on CI, so this is updating `ruff` for CI. That's the most significant effect of this change. (`pre-commit` is run for linting on CI probably much more often than it is used locally, to manage pre-commit hooks or otherwise, in GitPython development.)
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Jun 8, 2025
This resolves two warnings about Ruff configuration, by: - No longer setting `ignore-init-module-imports = true` explicitly, which was deprecated since `ruff` 0.4.4. We primarily use `ruff` via `pre-commit`, for which this deprecation has applied since we upgraded the version in `.pre-commit-config.yaml` from 0.4.3 to 0.6.0 in d1582d1 (gitpython-developers#1953). We continue to list `F401` ("Module imported but unused") as not automatically fixable, to avoid inadvertently removing imports that may be needed. See also: https://docs.astral.sh/ruff/settings/#lint_ignore-init-module-imports - Rename the rule `TCH004` to `TC004`, since `TCH004` is the old name that may eventually be removed and that is deprecated since 0.8.0. We upgraded `ruff` in `.pre-commit-config.yml` again in b7ce712 (gitpython-developers#2031), from 0.6.0 to 0.11.12, at which point this deprecation applied. See also https://astral.sh/blog/ruff-v0.8.0. These changes make those configuration-related warnings go away, and no new diagnostics (errors/warnings) are produced when running `ruff check` or `pre-commit --all-files`. No F401-related diagnostics are triggered when testing with explicit `ignore-init-module-imports = false`, in preview mode or otherwise. This commit also adds the version lower bound `>=0.8` for `ruff` in `requirements-dev.txt`. (That file is rarely used, as noted in a8a73ff (gitpython-developers#1871), but as long as we have it, there may be a benefit to excluding dependency versions for which our configuration is no longer compatible.)
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Jun 8, 2025
This resolves two warnings about Ruff configuration, by: - No longer setting `ignore-init-module-imports = true` explicitly, which was deprecated since `ruff` 0.4.4. We primarily use `ruff` via `pre-commit`, for which this deprecation has applied since we upgraded the version in `.pre-commit-config.yaml` from 0.4.3 to 0.6.0 in d1582d1 (gitpython-developers#1953). We continue to list `F401` ("Module imported but unused") as not automatically fixable, to avoid inadvertently removing imports that may be needed. See also: https://docs.astral.sh/ruff/settings/#lint_ignore-init-module-imports - Rename the rule `TCH004` to `TC004`, since `TCH004` is the old name that may eventually be removed and that is deprecated since 0.8.0. We upgraded `ruff` in `.pre-commit-config.yml` again in b7ce712 (gitpython-developers#2031), from 0.6.0 to 0.11.12, at which point this deprecation applied. See also https://astral.sh/blog/ruff-v0.8.0. These changes make those configuration-related warnings go away, and no new diagnostics (errors/warnings) are produced when running `ruff check` or `pre-commit run --all-files`. No F401-related diagnostics are triggered when testing with explicit `ignore-init-module-imports = false`, in preview mode or otherwise. In addition, this commit makes two changes that are not needed to resolve warnings: - Stop excluding `E203` ("Whitespace before ':'"). That diagnostic is no longer failing with the current code here in the current version of `ruff`, and code changes that would cause it to fail would likely be accidentally mis-st - Add the version lower bound `>=0.8` for `ruff` in `requirements-dev.txt`. That file is rarely used, as noted in a8a73ff (gitpython-developers#1871), but as long as we have it, there may be a benefit to excluding dependency versions for which our configuration is no longer compatible. This is the only change in this commit outside of `pyproject.toml`.
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Oct 25, 2026
The tox `misc` environment runs `pre-commit run --all-files` with `SKIP = ruff-format,ruff`, so that it covers the other hooks and leaves Ruff to the separate `ruff` and `format` environments. Later, b7ce712 (gitpython-developers#2031) switched the Ruff linting hook in `.pre-commit-config.yaml` from its id `ruff`, which `ruff-pre-commit` now keeps only as a legacy alias, to `ruff-check`, but the `SKIP` list was not updated. pre-commit ignores unknown hook ids in `SKIP`, so `tox -e misc` has been running `ruff check` again, duplicating the `ruff` environment: ruff check...........................................Passed ruff format..........................................Skipped Skip `ruff-check` instead of `ruff`. Run locally with tox 4.67.1, `tox -e misc` now reports both Ruff hooks as `Skipped`, and all the other hooks (`shellcheck`, the `pre-commit-hooks` checks, and `validate-pyproject`) still run and pass. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Oct 25, 2026
The tox `misc` environment runs `pre-commit run --all-files` with `SKIP = ruff-format,ruff`, so that it covers the other hooks and leaves Ruff to the separate `ruff` and `format` environments. Later, b7ce712 (gitpython-developers#2031) switched the Ruff linting hook in `.pre-commit-config.yaml` from its id `ruff`, which `ruff-pre-commit` now keeps only as a legacy alias, to `ruff-check`, but the `SKIP` list was not updated. pre-commit ignores unknown hook ids in `SKIP`, so `tox -e misc` has been running `ruff check` again, duplicating the `ruff` environment: ruff check...........................................Passed ruff format..........................................Skipped Skip `ruff-check` instead of `ruff`. Run locally with tox 4.67.1, `tox -e misc` now reports both Ruff hooks as `Skipped`, and all the other hooks (`shellcheck`, the `pre-commit-hooks` checks, and `validate-pyproject`) still run and pass. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Oct 25, 2026
The main CI does not use tox, so the tox configuration can break without anyone noticing. It has: `tox -e html` stopped working when 9e54de4 (gitpython-developers#2243) removed the `doc` extra, `tox -e misc` has run `ruff check` again since b7ce712 (gitpython-developers#2031) changed that hook's id, and the `base_python` fallbacks have not meant what they said since 62c024e (gitpython-developers#1693). New releases of tox and virtualenv can also change how the configuration behaves, as when tox 4.56.0 made missing interpreters fail. But running every tox environment is too slow for every push and pull request. Add a `tox` workflow that runs on a weekly schedule and through `workflow_dispatch`. Each job runs the tox environments for one Python version, from 3.8 to 3.15, on Ubuntu. 3.8 and 3.9 run on `ubuntu-24.04`, since `setup-python` has no builds of them for Ubuntu 26.04. The 3.12 job also runs `gix`, and the 3.13 job also runs `ruff`, `format`, `mypy`, `html`, and `misc`. The steps that prepare for the tests (Rust for GixPython source builds, current Git from the git-core PPA, `init-tests-after-clone.sh`, and the test Git identity and aliases) are the same as in `pythonpackage.yml`. tox and the plugin used below both need Python 3.11 or later, so `setup-python` also installs Python 3.13, and tox runs on that. tox is installed unpinned, so that the workflow tests the configuration with the tox and virtualenv that a contributor would get. The job has only `contents: read` and uses no secrets. For running tox on GitHub Actions, there are two tox plugins and one action: - `tox-gh`, from the `tox-dev` organization that maintains tox, selects the environments for the job's Python version from a mapping in the tox configuration, puts each environment's output in its own log group, and summarizes the results. - `tox-gh-actions`, an older plugin maintained outside `tox-dev`, does the same with more ways to select environments, and also supports tox 3. This project needs only selection by Python version. - `fedora-python/tox-github-action` runs tox in a Fedora container that has most Python versions, but no longer 3.8. It also pulls its image by a mutable tag, its repository has no license, and it runs tox as root in the container, which would change what GitPython's tests see about file ownership and `safe.directory`. Use `tox-gh`. Selecting environments by version is simple here, but the log groups make long weekly logs easier to read, and it adds little risk, since it comes from the `tox-dev` organization, like tox itself. Its mapping goes in `[tool.tox.gh.python]` in `pyproject.toml`. tox-gh does nothing outside GitHub Actions, and without it, `tox config` only adds a note that `gh` is unused. The job sets `TOX_GH_MAJOR_MINOR` to the matrix version, as tox-gh documents for when tox runs on a different Python. `actionlint`, `zizmor` 1.31.1 (pedantic, with online audits), and `pinact run --check --verify-comment` report nothing for the new workflow, and all pre-commit hooks pass. With `GITHUB_ACTIONS=true` set locally, tox with tox-gh ran only `py38` for `TOX_GH_MAJOR_MINOR=3.8`, in its own log group, and set up `py313`, `ruff`, `format`, `mypy`, `html`, and `misc` for 3.13. The workflow itself has not run on GitHub yet, because `workflow_dispatch` and `schedule` only work once it is on the default branch. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Oct 25, 2026
The tox `misc` environment runs `pre-commit run --all-files` with `SKIP = ruff-format,ruff`, so that it covers the other hooks and leaves Ruff to the separate `ruff` and `format` environments. Later, b7ce712 (gitpython-developers#2031) switched the Ruff linting hook in `.pre-commit-config.yaml` from its id `ruff`, which `ruff-pre-commit` now keeps only as a legacy alias, to `ruff-check`, but the `SKIP` list was not updated. pre-commit ignores unknown hook ids in `SKIP`, so `tox -e misc` has been running `ruff check` again, duplicating the `ruff` environment: ruff check...........................................Passed ruff format..........................................Skipped Skip `ruff-check` instead of `ruff`. Run locally with tox 4.67.1, `tox -e misc` now reports both Ruff hooks as `Skipped`, and all the other hooks (`shellcheck`, the `pre-commit-hooks` checks, and `validate-pyproject`) still run and pass. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this pull request
Oct 25, 2026
The main CI does not use tox, so the tox configuration can break without anyone noticing. It has: `tox -e html` stopped working when 9e54de4 (gitpython-developers#2243) removed the `doc` extra, `tox -e misc` has run `ruff check` again since b7ce712 (gitpython-developers#2031) changed that hook's id, and the `base_python` fallbacks have not meant what they said since 62c024e (gitpython-developers#1693). New releases of tox and virtualenv can also change how the configuration behaves, as when tox 4.56.0 made missing interpreters fail. But running every tox environment is too slow for every push and pull request. Add a `tox` workflow that runs on a weekly schedule and through `workflow_dispatch`. Each job runs the tox environments for one Python version, from 3.8 to 3.15, on Ubuntu. 3.8 and 3.9 run on `ubuntu-24.04`, since `setup-python` has no builds of them for Ubuntu 26.04. The 3.12 job also runs `gix`, and the 3.13 job also runs `ruff`, `format`, `mypy`, `html`, and `misc`. The steps that prepare for the tests (Rust for GixPython source builds, current Git from the git-core PPA, `init-tests-after-clone.sh`, and the test Git identity and aliases) are the same as in `pythonpackage.yml`. tox and the plugin used below both need Python 3.11 or later, so `setup-python` also installs Python 3.13, and tox runs on that. tox is installed unpinned, so that the workflow tests the configuration with the tox and virtualenv that a contributor would get. The job has only `contents: read` and uses no secrets. For running tox on GitHub Actions, there are two tox plugins and one action: - `tox-gh`, from the `tox-dev` organization that maintains tox, selects the environments for the job's Python version from a mapping in the tox configuration, puts each environment's output in its own log group, and summarizes the results. - `tox-gh-actions`, an older plugin maintained outside `tox-dev`, does the same with more ways to select environments, and also supports tox 3. This project needs only selection by Python version. - `fedora-python/tox-github-action` runs tox in a Fedora container that has most Python versions, but no longer 3.8. It also pulls its image by a mutable tag, its repository has no license, and it runs tox as root in the container, which would change what GitPython's tests see about file ownership and `safe.directory`. Use `tox-gh`. Selecting environments by version is simple here, but the log groups make long weekly logs easier to read, and it adds little risk, since it comes from the `tox-dev` organization, like tox itself. Its mapping goes in `[tool.tox.gh.python]` in `pyproject.toml`. tox-gh does nothing outside GitHub Actions, and without it, `tox config` only adds a note that `gh` is unused. The job sets `TOX_GH_MAJOR_MINOR` to the matrix version, as tox-gh documents for when tox runs on a different Python. `actionlint`, `zizmor` 1.31.1 (pedantic, with online audits), and `pinact run --check --verify-comment` report nothing for the new workflow, and all pre-commit hooks pass. With `GITHUB_ACTIONS=true` set locally, tox with tox-gh ran only `py38` for `TOX_GH_MAJOR_MINOR=3.8`, in its own log group, and set up `py313`, `ruff`, `format`, `mypy`, `html`, and `misc` for 3.13. The workflow itself has not run on GitHub yet, because `workflow_dispatch` and `schedule` only work once it is on the default branch. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This updates
ruffin.pre-commit-config.yamlfrom 0.6.0 to 0.11.12, changes itsidfrom the legacyruffalias toruff-check(which is better distinguished fromruff-format, which we also have a hook for), and applies the few style changes it newly recommends throughout the code. The style changes seem to make things slightly clearer overall.This also updates some other pre-commit hooks, but those don't require any changes to the code.
Currently the
ruffdependency inrequirements-dev.txtdoesn't specify a version, so no change is needed there. This update may be seen as bringing thepre-commitversion in line with what users will usually have locally withpip install -e ".[test]".The
pre-commithooks are how linting is currently done on CI, so this is updatingrufffor CI. That's the most significant effect of this change. (pre-commitis run for linting on CI probably much more often than it is used locally, to manage pre-commit hooks or otherwise, in GitPython development.)This works locally and on CI, but I'll still wait for all checks to pass before merging.